<template>
    <d2-container type="card">
        <header>
            <el-form :inline="true" :model="selectFrom" class="demo-form-inline" size="mini">
                <el-form-item label="客户名称">
                    <el-input v-model="selectFrom.name" placeholder="客户名称"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary">查询</el-button>
                </el-form-item>
            </el-form>
        </header>
        <footer>
            <el-table :data="tableData" border style="width: 100%" size="mini" :height="height">
                <el-table-column prop="id" label="外卖订单ID" align="center">
                </el-table-column>
                <el-table-column prop="callNumber" label="叫号" align="center">
                </el-table-column>
                <el-table-column label="用户名称" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.userInfo">{{ scope.row.userInfo.name }}</div>
                    </template>
                </el-table-column>
                <el-table-column prop="price" label="价格" align="center">
                </el-table-column>
                <el-table-column prop="connectTime" label="接单时间" align="center">
                </el-table-column>
                <el-table-column prop="reachTime" label="送达时间" align="center">
                </el-table-column>
                <el-table-column label="配送人" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.deliveryInfo">{{ scope.row.deliveryInfo.name }}</div>
                    </template>
                </el-table-column>
                <el-table-column prop="deliveryPrice" label="配送费" align="center">
                </el-table-column>
                <el-table-column prop="userAddress" label="配送地址" align="center">
                </el-table-column>
                <el-table-column label="支付方式" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.paymentMethod == 0">微信支付</div>
                        <div v-if="scope.row.paymentMethod == 1">储蓄支付</div>
                    </template>
                </el-table-column>
                <el-table-column prop="schoolId" label="校区" align="center">
                </el-table-column>
                <el-table-column prop="schoolBuildingId" label="校区楼栋" align="center">
                </el-table-column>
                <el-table-column prop="phone" label="手机号" align="center">
                </el-table-column>
                <el-table-column prop="contacts" label="联系人" align="center">
                </el-table-column>
                <el-table-column label="店铺" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.shopInfo">{{ scope.row.shopInfo.name }}</div>
                    </template>
                </el-table-column>
                <el-table-column label="支付状态" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.payState == 0">待支付</div>
                        <div v-if="scope.row.payState == 1">已支付</div>
                        <div v-if="scope.row.payState == 2">已完成</div>
                        <div v-if="scope.row.payState == 3">取消订单</div>
                        <div v-if="scope.row.payState == 4">取消完成</div>
                        <div v-if="scope.row.payState == 5">申请投诉</div>
                        <div v-if="scope.row.payState == 6">投诉完成</div>
                    </template>
                </el-table-column>
                <el-table-column label="配送状态" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.deliveryState == 0">未配送</div>
                        <div v-if="scope.row.deliveryState == 1">已接单【取餐中】</div>
                        <div v-if="scope.row.deliveryState == 2">已取餐【配送中】</div>
                        <div v-if="scope.row.deliveryState == 3">已送达</div>
                    </template>
                </el-table-column>
                <el-table-column label="出餐状态" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.shopState == 0">出餐中</div>
                        <div v-if="scope.row.shopState == 1">已出餐</div>
                        <div v-if="scope.row.shopState == 2">已完成</div>
                        <div v-if="scope.row.shopState == 3">取消订单</div>
                        <div v-if="scope.row.shopState == 3">取消完成</div>
                    </template>
                </el-table-column>
                <el-table-column prop="payTime" label="支付时间" align="center">
                </el-table-column>
                <el-table-column prop="notes" label="备注" align="center">
                </el-table-column>
                <el-table-column prop="okTime" label="客户确认时间" align="center">
                </el-table-column>
                <el-table-column prop="packingCharge" label="打包费" align="center">
                </el-table-column>
                <el-table-column prop="discountDetails" label="折扣详情" align="center">
                </el-table-column>
                <el-table-column prop="diningTime" label="出餐时间" align="center">
                </el-table-column>
                <el-table-column label="是否评价" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.isEvaluate == 0">未评价</div>
                        <div v-if="scope.row.isEvaluate == 1">已评价</div>
                    </template>
                </el-table-column>
                <el-table-column prop="pickingTime" label="取餐时间" align="center">
                </el-table-column>
                <el-table-column prop="savingsPrice" label="节省金额" align="center">
                </el-table-column>
                <el-table-column prop="createTime" label="创建时间" align="center">
                </el-table-column>
            </el-table>
            <div class="block" style="text-align:center">
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page"
                    :page-sizes="[5, 10, 15, 20]" :page-size="limit" layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
                </el-pagination>
            </div>
        </footer>
    </d2-container>
</template>
  
<script>
import { getOrderTakeaway } from "@/api/modules/order_takeaway.js"
export default {
    name: 'orderTakeaway',
    data() {
        return {
            selectFrom: {},//搜索栏
            tableData: [],//表格数据
            page: 1,
            limit: 10,
            total: 0,
            height: window.innerHeight - 250, //表格高度
        }
    },
    mounted() {
        this.getOrderTakeawayData();
        //-------------------------表格响应----------------//
        this.createHeight();
        //当页面发生变化时，表格高度固定
        window.onresize = () => {
            return (() => {
                this.$nextTick(() => {
                    this.createHeight();
                });
            })();
        };
    },
    methods: {
        //获取外卖订单
        getOrderTakeawayData(){
            this.selectFrom.page = this.page;
            this.selectFrom.limit = this.limit;
            getOrderTakeaway(this.selectFrom).then(res=>{
                this.tableData = res.dataList;
                this.total = res.total;
            })
        },
        handleSizeChange(val) {
            this.limit = val;
            this.getOrderTakeawayData();
        },
        handleCurrentChange(val) {
            this.page = val;
            this.getOrderTakeawayData();
        },
        //---------------自动变更表格高度------------------//
        createHeight() {
            this.height = window.innerHeight - 250;
        }
    }
}
</script>
  